<template>
  <div>
    <el-dialog title="提示" :visible.sync="obj.isTrue" width="50%">
      <el-form ref="form" :model="form" label-width="80px">
        <el-form-item label="限时秒杀名称">
          <el-input v-model="form.title"></el-input>
        </el-form-item>

        <span class="demonstration">活动时间</span>
        <el-date-picker
          v-model="time"
          value-format="yyyy-MM-dd"
          type="datetimerange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        >
        </el-date-picker>
        <el-form-item label="商品一级分类编号">
          <el-select
            @change="changeCate()"
            v-model="form.first_cateid"
            placeholder="请选择活动区域"
          >
            <el-option
              v-for="(item, index) in acte"
              :key="index"
              :value="item.id"
              :label="item.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="商品二级分类编号">
          <el-select v-model="form.second_cateid" placeholder="请选择活动区域">
            <el-option
              v-for="(item, index) in secondCate"
              :key="index"
              :value="item.id"
              :label="item.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="商品编号">
          <el-input v-model="form.name"></el-input>
        </el-form-item>
        <el-form-item label="状态">
          <el-switch
            v-model="form.status"
            :active-value="1"
            :inactive-value="2"
          ></el-switch>
        </el-form-item>
      </el-form>

      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="add()">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { seckadd, catelist } from "../../../request/api.js";
import { mapActions, mapGetters } from "vuex";
export default {
  props: ["obj"],
  data() {
    return {
      form: {
        title: "",
        begintime: [],
        endtime: [],
        first_cateid: "",
        second_cateid: "",
        goodsid: "",
        status: 1,
      },
      time: [],
      secondCate: [],
      pickerOptions: {
        shortcuts: [
          {
            text: "最近一周",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近一个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近三个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit("pick", [start, end]);
            },
          },
        ],
      },
      value1: [new Date(2000, 10, 10, 10, 10), new Date(2000, 10, 11, 10, 10)],
      value2: "",
    };
  },
  computed: {
    ...mapGetters({
      acte: "cate/list",
      // specs: "specs/list",
    }),
  },
  methods: {
    ...mapActions({
      catelist: "cate/asyncChangeList",
      // specslist: "specs/asyncChangeList",
    }),
    //一级分类发生变化
    changeCate() {
      catelist({ pid: this.form.first_cateid }).then((res) => {
        this.form.second_cateid = "";
        this.secondCate = res.data.list;
      });
    },
    add() {
      console.log(this.time);
      // console.log(this.time[0], this.time[1]);
      this.form.begintime = this.time[0];
      this.form.endtime = this.time[1];
      console.log(this.form.begintime, this.form.endtime);
      console.log(this.form);
    },
  },
  mounted() {
    this.catelist();
    // this.specslist();
  },
};
</script>

<style>
</style>